/*
 * @Author: dadadaXU 1413107032@qq.com
 * @Date: 2024-12-30 12:50:44
 * @LastEditors: dadadaXU 1413107032@qq.com
 * @LastEditTime: 2025-01-05 16:22:46
 * @FilePath: /FileBackup/test/test_FilePacker.cpp
 * @Description: 文件打包模块测试
 */
#include <gtest/gtest.h>
#include <iostream>
#include <vector>
#include <string>
#include "../include/filePacker.hpp"

class FilePackerTest : public ::testing::Test
{
protected:
    FileFilterArguments filterArgument = {0};
    std::filesystem::path sourceFilePath, packPath;
};

/**
 * 1. packer_all: 无文件过滤
 * 2. packer_filter_path: 过滤文件路径（包含有“2”的路径）
 */
TEST_F(FilePackerTest, packer_all)
{
    sourceFilePath = std::filesystem::path("/home/dadada/Develop/SoftwareEngineering/FileBackup/test/testSample");
    packPath = std::filesystem::path("../testPackage/packer_all");
    FilePacker packer(sourceFilePath, packPath);

    filterArgument.mode = 0;
    std::string message("无文件过滤");

    packer.PackFile(filterArgument, message);
}

TEST_F(FilePackerTest, unpacker_all)
{
    sourceFilePath = std::filesystem::path("../testPackage/packer_all.pak");
    packPath = std::filesystem::path("../testRecover/unpacker_all");
    FilePacker packer(sourceFilePath, packPath);

    EXPECT_TRUE(packer.UnpackFile(true, false));
}

TEST_F(FilePackerTest, packer_filter_path)
{
    sourceFilePath = std::filesystem::path("/home/dadada/Develop/SoftwareEngineering/FileBackup/test/testSample");
    packPath = std::filesystem::path("../testPackage/packer_filter_path");
    FilePacker packer(sourceFilePath, packPath);

    filterArgument.mode = FILE_FILTER_PATH;
    filterArgument.path = std::string("^[^2]*$");
    std::string message("过滤文件路径（不包含有“2”的路径）");

    packer.PackFile(filterArgument, message);
}

TEST_F(FilePackerTest, unpacker_filter_path)
{
    sourceFilePath = std::filesystem::path("../testPackage/packer_filter_path.pak");
    packPath = std::filesystem::path("../testRecover/unpacker_filter_path");
    FilePacker packer(sourceFilePath, packPath);

    EXPECT_TRUE(packer.UnpackFile(true, false));
}

TEST_F(FilePackerTest, packer_filter_size)
{
    sourceFilePath = std::filesystem::path("/home/dadada/Develop/SoftwareEngineering/FileBackup/test/testSample");
    packPath = std::filesystem::path("../testPackage/packer_filter_size");
    FilePacker packer(sourceFilePath, packPath);

    filterArgument.mode = FILE_FILTER_SIZE;
    filterArgument.size_from = 0;
    filterArgument.size_to = 1024;
    std::string message("过滤文件大小 < 1KB");

    packer.PackFile(filterArgument, message);
}

TEST_F(FilePackerTest, unpacker_filter_size)
{
    sourceFilePath = std::filesystem::path("../testPackage/packer_filter_size.pak");
    packPath = std::filesystem::path("../testRecover/unpacker_filter_size");
    FilePacker packer(sourceFilePath, packPath);

    EXPECT_TRUE(packer.UnpackFile(true, false));
}

int main(int argc, char **argv)
{
    ::testing::InitGoogleTest(&argc, argv);

    return RUN_ALL_TESTS();
}
